home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C++
/
Applications
/
NeuroSim 1.0
/
.cp
/
CStdNeuron.cp
< prev
next >
Wrap
Text File
|
1996-02-19
|
4KB
|
135 lines
// ===========================================================================
// CStdNeuron.cp ©1996 Timo Eloranta
// ===========================================================================
// A concrete neuron class derived from the abstract CNeuron class
#include "CStdNeuron.h"
#include "CNeuralNet.h"
#include "NS_Utils.h" // PlayOneSnd
#include <LListIterator.h> // PowerPlant header
// ---------------------------------------------------------------------------
// • DoClickAction
//
// Called by: CNeuroSimPane::ClickSelf
// CNeuralNet::SpendTime
// ---------------------------------------------------------------------------
// React to a mouse click inside this neuron. If the neuron is
// a receptor (and the option key is not pressed) we add the neuron
// to the "light up queue" and process the queue right away.
// With "ordinary" neurons (and receptors when option key is pressed!)
// we show the user the neurons which are connected to this neuron by
// coloring the connections and by marking the "destination" neurons
// with a yellow ring.
void
CStdNeuron::DoClickAction( Boolean inOptionKeyDown )
{
LListIterator theScanner( mNextOnes, iterate_FromStart );
CNeuronPtr theNext;
if ( IsReceptor() && !inOptionKeyDown ) {
PlayOneSnd( snd_Click, true );
SetNeuronState( mMaxState + 1 ); // To get the right color
sNet -> AddToLightQ( (LLink *) this );
sNet -> ProcessLightQ();
} else {
// Color the connections and show the connected neurons
while ( theScanner.Next( &theNext ))
theNext -> SetDestinationFlag( true );
mConnDirty = mConnLit = true;
sNet -> SetNeuronsDirty( mConnRect );
sNet -> RequestDraw();
// Hold on as long as the mouse button is pushed
while ( ::StillDown() ) { };
// Restore the drawing
theScanner.ResetTo( iterate_FromStart );
while ( theScanner.Next( &theNext ))
theNext -> SetDestinationFlag( false );
mConnDirty = true;
mConnLit = false;
sNet -> SetNeuronsDirty( mConnRect );
sNet -> RequestDraw();
};
}
// ---------------------------------------------------------------------------
// • ShouldLightUp
//
// Called by: CNeuron::IncState
// ---------------------------------------------------------------------------
// Return true if the state of this neuron is such that it should
// be in the "light up queue".
inline Boolean
CStdNeuron::ShouldLightUp() const
{
return mState > mMaxState;
}
// ---------------------------------------------------------------------------
// • DoLightUpAction
//
// Called by: CNeuralNet::ProcessLightQ
// ---------------------------------------------------------------------------
// Here we define what happens when a neuron lights up.
void
CStdNeuron::DoLightUpAction()
{
LListIterator theScanner( mNextOnes, iterate_FromStart );
CNeuronPtr theNext;
// Force the connections starting from this neuron
// to be redrawn with some bright color (yellow).
mConnDirty = mConnLit = true;
// Force the surrounding neurons to be redrawn
// because drawing connections might mess them up
sNet -> SetNeuronsDirty( mConnRect );
// Increase the state of the connected nodes
while ( theScanner.Next( &theNext ) )
theNext -> IncState();
}
// ---------------------------------------------------------------------------
// • SetPostLightUpState
//
// Called by: CNeuralNet::ProcessLightQ
// ---------------------------------------------------------------------------
// Here we define what happens when a neuron fades back to normal
// after lighting up.
void
CStdNeuron::SetPostLightUpState()
{
// Restore the normal color to the connections
mConnDirty = true;
mConnLit = false;
// The surrounding neurons have to be redrawn
// because drawing connections might mess them up...
sNet -> SetNeuronsDirty( mConnRect );
// And finally... set the state of this neuron back to 0.
SetNeuronState( 0 );
}